//
//  CustomCarOrder.swift
//  Composite
//
//  Created by LY on 2017/10/26.
//  Copyright © 2017年 DesignPatterns. All rights reserved.
//

import Foundation
class CustomCarOrder {
    let customer:String
    let parts:[carPart]
    init(name:String,Parts:carPart...) {
        customer = name
        parts = Parts
    }
    func prinAll(){
        print("Customer \(customer) \n Cost:\(formatCurrencyString(number: totoalPrice))")
    }
    var totoalPrice:Float{
        return parts.reduce(0, { (total, item:carPart) -> Float in
            return total + item.price
        })
    }
    func formatCurrencyString(number:Float) -> String{
        let formatter = NumberFormatter()
        formatter.numberStyle = .currency
        return formatter.string(for: number) ?? ""
    }
}
class AAAA: carPart {
    var name: String
    var price: Float
    init(nane:String,description:String,category:String) {
        fatalError("Not Implemented")
    }
}
